const { smart } = require('webpack-merge')
const base = require('./webpack.common.js')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = smart(base, {
  mode: 'development',
  devtool: 'cheap-module-eval-source-map',
  output: {
    filename: '[name].js'
  },
  devServer: {
    port: 8081,
    progress: true,
    open: true,
    hot: true,
    inline: true,
    compress: true,
    historyApiFallback: true,
    contentBase: './public',
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        pathReWrite: { '^/api': '' },
        changeOrigin: true
      }
    }
  },
  plugins: [
    new HtmlWebpackPlugin({
      url: './',
      title: 'luohao webpack homework',
      template: './public/index.html',
      filename: 'index.html'
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin()
  ]
})
